package com.example.service.webhook.business.jingdong.repository;

import com.example.service.webhook.business.jingdong.entity.JdJinTiaoBillEntity;
import com.example.service.webhook.repository.base.BaseDAO;
import com.example.service.webhook.util.DateUtil;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * @author liyang
 * @email liyang@51dojo.com
 * @create 2017-10-24 上午11:03
 * @description 京东金条
 **/
@Repository
public class JdJinTiaoBillRepository extends BaseDAO<JdJinTiaoBillEntity>{

    @Resource(name="templateJingdong")
    private JdbcTemplate jdbcTemplate;

    public JdbcTemplate getJdbcTemplate() {
        return jdbcTemplate;
    }

    public void saveJinTiaoBill(JdJinTiaoBillEntity entity)throws Exception  {
        entity.setCreateTime(DateUtil.getCurrentDate());
        entity.setLastModifyTime(DateUtil.getCurrentDate());
        this.add(entity);
    }

    public void updateJinTiaoBill(JdJinTiaoBillEntity entity) throws Exception  {
        entity.setLastModifyTime(DateUtil.getCurrentDate());
        this.modify(entity);
    }

    public JdJinTiaoBillEntity getJinTiaoBillEntity(String userId,String mappingId,String loanId) throws Exception {
        String sql = "";
        String tableName = "t_jd_jintiaobill";
        sql = "select * from " + tableName + " where userId=? and mappingId=? and loanId=?";
        JdJinTiaoBillEntity pojo = null;
        try{
            pojo = (JdJinTiaoBillEntity) queryOne(sql, new Object[] { userId,mappingId,loanId}, new JdJinTiaoBillEntity());
        }catch(EmptyResultDataAccessException e){
            return null;
        }

        return pojo;
    }
}
